<?php
class Admin_Model_DbTable_Categories extends Zend_Db_Table_Abstract
{
	
	protected $_name = 'categories';
	protected $_id = 'id';	
	
	//Récupérer tous les produits
	public function getAllCaterories()
	{
		$categories = $this->fetchAll();
		return $categories;
	}
	
	public function obtenirCategorie($id)
	{
		$id = (int)$id;
		$row = $this->fetchRow('id = ' . $id);
		
// 		$id = (int) $id;
// 		$select = $this->select();
// 		$select->where('id = ?', $id);
// 		$row = $this->fetchRow($select);
	
		if (!$row) {
			throw new Exception("Count not find row $id");
		}	
		return $row->toArray();
	}
	
	public function editeCategorie($id, $name)
	{
		$data = array(
				'name' => $name
		);
		$this->update($data, 'id = '. (int)$id);
	}
	
	public function addCategorie($name)
	{
		$data = array(
				'name' => $name
		);
		return $this->insert($data);
	}
	                 
	public function deleteCategorie($id)
	{
		$this->delete('id =' . (int)$id);
		
	}
	
}